#include <cstdio>
#include <cstring>

typedef long long ll;
const int N = 1005, mod = 1e9 + 7;
int n, k, t;
ll f[N][N], fac[N] = {1}, inv[N], ans[N][N];

inline int qpow(ll base, int exp) {
  ll res = 1;
  while (exp) {
    if (exp & 1) res = res * base % mod;
    base = base * base % mod;
    exp >>= 1;
  }
  return res;
}

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }

inline ll A(int n, int m) {
  if (n < m) return 0;
  return fac[n] * inv[n - m] % mod;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("CF403D Beautiful Pairs of Numbers.in", "r", stdin);
  freopen("CF403D Beautiful Pairs of Numbers.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  for (int i = 1; i < N; ++i) fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = qpow(fac[N - 1], mod - 2), inv[0] = 1;
  for (int i = N - 2; i; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
  f[0][0] = 1;
  for (int i = 1; i <= 45; ++i) {
    for (int j = (i + 1) * i >> 1; j < N; ++j)
      f[i][j] = add(f[i][j - i], f[i - 1][j - i]);
  }
  for (int i = 1; i < N; ++i) {
    for (int j = 1; j <= 45; ++j) {
      for (int k = j * (j + 1) >> 1; k <= i; ++k)
        ans[i][j] += 1ll * f[j][k] * A(i - k + j, j) % mod, ans[i][j] %= mod;
    }
  }
  while (t--) {
    scanf("%d%d", &n, &k);
    printf("%lld\n", ans[n][k]);
  }
  return 0;
}